<?php

/**
 * $Id: EditorClass.inc.php 1967 2012-09-19 10:06:57Z 5330056@qq.com $
 */
class EditorClass
{
	private $_editorSize = array();
	private $_tplPath = '';
	private $_editorProperty = array('name'=>'editorContent', 'class'=>'');
	private $_editorStyle = 'default';
	
	public function __construct($width = 800, $height = 500)
	{
		$this->setEditorProperty(array('width'=>intval($width), 'height'=>intval($height)));
		$this->_tplPath = G_APP_ROOT.'/editor_tpl';
	}
	
	public function setEditorProperty($propertyArr)
	{
		foreach($propertyArr as $pName=>$pValue)
		{
			$this->_editorProperty[$pName] = $pValue;
		}
	}

	public function setStyle($style)
	{
		
	}
	
	public function getEditorCode()
	{
		$tplFile = $this->_tplPath.'/'.$this->_editorStyle.'.tpl.html';
		if(!file_exists($tplFile))
		{
			return '';
		}
	
		$replaceArr = array();
		foreach($this->_editorProperty as $pName=>$pValue)
		{
			if(in_array($pName, array('name', 'width', 'height', 'class')))
			{
				$replaceArr['p'][] = '{'.$pName.'}';
				$replaceArr['r'][] = $pValue;
			}
			else
			{
				$replaceArr['p'][] = '{property}';
				$replaceArr['r'][] = $pName.'="'."{$pValue}\" {property}";
			}
		}
		$replaceArr['p'][] = '{property}';
		$replaceArr['r'][] = '';
		return str_replace($replaceArr['p'], $replaceArr['r'], file_get_contents($tplFile));
	}
	
	public function getEditorLoadJS()
	{
		return '<script charset="utf-8" src="http://static.ituwang.com/common/onlineEditor/kindeditor/kindeditor-min.js"></script>'."\n".'<script charset="utf-8" src="http://static.ituwang.com/common/onlineEditor/kindeditor/lang/zh_CN.js"></script>';
	}
	
}